package design_pattern.study.Iterator;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class StudentIteratorImpl implements StudentIterator {
    private List<Student> list;
    private AtomicInteger position = new AtomicInteger(0);

    public StudentIteratorImpl(List<Student> list) {
        this.list = list;
    }

    @Override
    public boolean hasNext() {
        return position.get() < list.size();
    }

    @Override
    public Student next() {
        Student currentStudent = list.get(position.get());
        position.incrementAndGet();
        return currentStudent;
    }
}
